angular.module('starter.controllers', [])

.controller('DashCtrl', function($rootScope, $scope, $ionicPopover) {

       
  $scope.doInquery = function(){    
    var l_cache = $rootScope.dbdict; 
    var l_search = $scope.dataInquery;
    //if (l_search.indexOf(')')<0 && l_search.indexOf('(')<0) 
    //  l_search = '(' + l_search + ')';
    
    var l_patt1 = new RegExp(l_search);   
    console.log('test', l_search);
    
    var limit = 0;
    var l_cache2 = {};
    $scope.inqueryLists = {};
    
    for (var i in l_cache) {      
      if (l_patt1.test(i)) {
        limit ++ ;
        if (limit > 200) { 
          console.log('out of 200', i, l_cache); 
          l_cache2[i] = '超出200个拉...';
          break; 
        }
        l_cache2[i] = l_cache[i];
      }  
    }
    $scope.inqueryLists = l_cache2;
  };
   
  $scope.onDoubleTap = function(){
      $scope.showPop();      
  }
  
  $ionicPopover.fromTemplateUrl('subListMenu.html',{scope:$scope})
    .then(function (popover) {
      $scope.popover = popover;
  })
  
  $scope.showPop = function ($event) {
      $scope.popover.show($event);
  }
  
  $scope.selectPop = function (choose) {
    
      var txtFocus = document.getElementById("inqueryWord");           
      var l_pos = 0;
      
      $scope.popover.hide();
      //alert(choose);
      switch(choose)
      {
      case 'start':
        $scope.dataInquery = '^()';
        l_pos = 2;
        break;
      case 'end':
        $scope.dataInquery = '()$';
        l_pos = 1;
        break;
      case 'include':
        $scope.dataInquery = '(|)';
        l_pos = 1;
        break;  
      case 'startend':
        $scope.dataInquery = '^().*(end)$';
        l_pos = 2;
        break;    
        
      default:
        $scope.dataInquery = ''
      }   
      //obj.setSelectionRange(startPosition, endPosition);
      
      setTimeout(function() {  
            txtFocus.focus();
            txtFocus.setSelectionRange(l_pos, l_pos);
      }, 100); 
          
      
  }
  
  
  
})

.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
});
